<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.been.Admin"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	String action=request.getParameter("action");
	String account=request.getParameter("account"); 
	if("login".equals(action)&&account.trim().length()>0){
		Admin admin=new Admin();
		admin.setAdminName(account);
		admin.setIp(request.getRemoteAddr());
		admin.setCreateTime(new Timestamp(new Date().getTime()));
		session.setAttribute("admin",admin);
		 response.sendRedirect(response.encodeRedirectURL(request.getRequestURI()));  
        return;
		
	}else if("logout".equals(action)){
		session.removeAttribute("admin");  
        response.sendRedirect(response.encodeRedirectURL(request.getRequestURI()));  
        return;  
	}
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'loginSingle.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <c:choose>
  	<c:when test="${sessionScope.admin!=null}">       <!-- admin不为空,即在线 -->
  	欢迎您，${admin.adminName }
  	</c:when>
  	<c:otherwise>           <!-- 不在线 -->
  		${msg }
  		<form action="${pageContext.request.requestURI }?action=login" method="post">
  		账号:	<input type="text" name="account" >
  			  <input type="submit" value="登录">  
  		</form>
  	</c:otherwise>
  </c:choose>
  </body>
</html>
